import 'package:base_flutter/base_flutter.dart';
import 'package:flustars_flutter3/flustars_flutter3.dart';
import 'package:flutter/material.dart';
import 'package:ls_work/a_elder/models/elder_entity.dart';
import 'package:ls_work/net/net.dart';
import 'package:ls_work/res/resources.dart';
import 'package:ls_work/widgets/gallery_photo_browser.dart';
import 'package:ls_work/widgets/load_image.dart';

import '../../util/ext_utils.dart';

class ElderHeaderImageCell extends StatefulWidget {
  final ElderInfo info;
  final int? headimageId;
  ElderHeaderImageCell({Key? key, required this.info, this.headimageId});
  @override
  _ElderHeaderImageCellState createState() => _ElderHeaderImageCellState();
}

class _ElderHeaderImageCellState extends State<ElderHeaderImageCell> {
  int _headimageId = 0;
  @override
  Widget build(BuildContext context) {
    if (widget.info == null) {
      return Container();
    }
    if (widget.headimageId != null) {
      _headimageId = widget.headimageId!;
    } else if (widget.info.headimageId != null) {
      _headimageId = widget.headimageId!;
    }
    String sexName = widget.info.sexName??"";
    String age = widget.info.age != null ? widget.info.age.toString() : '';
    String buildingNo = widget.info.buildingNo??"";
    String floorNo = widget.info.floorNo ??'';
    String roomNo = widget.info.roomNo ?? '';
    String nurseLevelName = widget.info.nurseLevelName ?? '';
    String statusSecondName = widget.info.statusSecondName ??'';
    return Container(
      width: ScreenUtil.getScreenW(context),
      padding: EdgeInsets.fromLTRB(12, 15, 5, 0),
      child: Column(
        mainAxisAlignment: MainAxisAlignment.start,
        crossAxisAlignment: CrossAxisAlignment.start,
        children: <Widget>[
          Row(
            mainAxisAlignment: MainAxisAlignment.start,
            crossAxisAlignment: CrossAxisAlignment.start,
            children: <Widget>[
              Column(
                mainAxisAlignment: MainAxisAlignment.start,
                crossAxisAlignment: CrossAxisAlignment.center,
                children: <Widget>[
                  GestureDetector(
                    behavior: HitTestBehavior.opaque,
                    onTap: () {
                      debugPrint('${HttpApi.imageHead}${widget.info.headimageId??0}');
                      showBigImage(context, ['${HttpApi.imageHead}${widget.info.headimageId??0}']);
                      // Navigator.push(
                      //   context,
                      //   MaterialPageRoute(
                      //     builder: (context) => GalleryPhotoViewWrapper(
                      //       galleryItems: [widget.info.headimageId??0],
                      //       backgroundDecoration: const BoxDecoration(
                      //         color: Colors.black,
                      //       ),
                      //       initialIndex: 0,
                      //     ),
                      //   ),
                      // );
                    },
                    child: Container(
                      width: 160,
                      height: 200,
                      decoration: BoxDecoration(color: Colours.bg_color),
                      child: widget.info != null
                          ? LoadImage(
                              "${HttpApi.imageDownLoadUrl}$_headimageId",
                              height: 100,
                              width: 80,
                              fit: BoxFit.fill,
                            )
                          : SizedBox(),
                    ),
                  ),
                  SizedBox(
                    height: 5,
                  ),
                ],
              ),
              SizedBox(
                width: 13,
              ),
              Column(
                mainAxisAlignment: MainAxisAlignment.start,
                crossAxisAlignment: CrossAxisAlignment.start,
                children: <Widget>[
                  Container(
                    width: ScreenUtil.getScreenW(context) - 190,
                    child: Row(
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                      crossAxisAlignment: CrossAxisAlignment.center,
                      children: <Widget>[
                        Text(
                          widget.info.name??"",
                          style: TextStyles.textBoldDark16,
                        ),
                        Text(
                          '', //38.5℃
                          style: TextStyles.textGray12,
                        ),
                      ],
                    ),
                  ),
                  SizedBox(
                    height: 5,
                  ),
                  Container(
                    width: ScreenUtil.getScreenW(context) - 190,
                    child: Text(
                      '$sexName  $age $buildingNo#$floorNo-$roomNo $nurseLevelName',
                      style: TextStyles.textGray14,
                    ),
                  ),
                  SizedBox(
                    height: 5,
                  ),
                  Chip(
                    label: Text('$statusSecondName',
                        style: TextStyle(color: Colors.orange)),
                    backgroundColor: Colors.orange[100],
                    shape: RoundedRectangleBorder(
                      borderRadius: BorderRadius.circular(2.0),
                    ),
                  ),
                ],
              ),
            ],
          ),
          SizedBox(
            height: 8,
          ),

          Wrap(
            spacing: 8,
            runSpacing: 8,
            children: (widget.info.tags??[]).map((e) => tagWidget(e)).toList(),
          ),

          Container(height: 10,),
          Container(
            height: 1,
            color: Colours.bg_gray,
            width: double.infinity,
          )
        ],
      ),
    );
  }

  Widget tagWidget(ElderTags tag){
    return CommonText(tag.tagsName,textSize: 14,textColor: Colors.white).addToContainer(padding: EdgeInsets.symmetric(horizontal: 5,vertical: 4),decoration: BoxDecoration(
        color: HexColor.fromHex(tag.color??"")??Colors.red,borderRadius: 2.borderRadius
    ));
  }
}
